﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shove.Web.UI;

public partial class UserControls_FindPwd : UCBase
{
    public UserControls_FindPwd()
    {
        Name = "找回密码";

        swpas = new ShoveWebPartAttribute[15];

        swpas[0] = new ShoveWebPartAttribute_Int("控件宽度", "1,1000", 759, "控件宽度");
        swpas[1] = new ShoveWebPartAttribute_Int("导航行高", "1,300", 28, "导航行高");
        swpas[2] = new ShoveWebPartAttribute_Int("导航单元格宽度", "", 106, "导航单元格宽度");
        swpas[3] = new ShoveWebPartAttribute_Int("标题行高", "1,500", 30, "提示标题行高");
        swpas[4] = new ShoveWebPartAttribute_Int("标题列的单元格宽度", "1,800", 136, "第二步标题列的单元格宽度");
        swpas[5] = new ShoveWebPartAttribute_Int("说明性文字行高", "1,500", 100, "说明性文字行高");
        swpas[6] = new ShoveWebPartAttribute_Int("文本框的宽度", "1,500", 120, "文本框的宽度");
      
        swpas[7] = new ShoveWebPartAttribute_Image("导航文本背景图片", "", "images/title_bg_1.jpg", "导航文本背景图片");
        swpas[8] = new ShoveWebPartAttribute_Image("导航空单元格背景图片", "", "images/title_bg_hui.jpg", "导航空单元格背景图片");
        swpas[9] = new ShoveWebPartAttribute_Image("确定按钮图片", "", "images/button_ok.jpg", "确定按钮图片");

        swpas[10] = new ShoveWebPartAttribute_Text("导航默认文本CSS样式", "", "title14_bai", "导航默认文本CSS样式");
        swpas[11] = new ShoveWebPartAttribute_Text("标题默认字CSS样式", "", "black12", "第一步默认字CSS样式");
        swpas[12] = new ShoveWebPartAttribute_Text("文本框CSS样式", "", "in_p2", "文本框CSS样式");
        swpas[13] = new ShoveWebPartAttribute_Text("说明文字的CSS样式", "", "black12", "说明文字的CSS样式");

        swpas[14] = new ShoveWebPartAttribute_Color("边框颜色", "#cccccc", "边框颜色");
    }

    private void InitlayOut()
    {
        tabctr.Width = swpAttributes[0];
        tabctr.BgColor = swpAttributes[14];
        tdsign.Height = swpAttributes[1];
        tdsign.Width = swpAttributes[2];
        tdsign.Attributes.Add("class", swpAttributes[10]);
        tdsign.Style.Add("background-image", "url('" + swpAttributes[7] + "')");
        tdspace.Style.Add("background-image", "url('" + swpAttributes[8] + "')");

        tdfrist.Height = swpAttributes[3];
        tdfrist.Attributes.Add("class", swpAttributes[11]);

        tdname.Attributes.Add("class", swpAttributes[11]);
        txtUserName.Width = new Unit(swpAttributes[6]);
        txtUserName.CssClass = swpAttributes[12];
        ibOK.ImageUrl = "~/" + swpAttributes[9];
        ibCommit.ImageUrl = "~/" + swpAttributes[9];

        tdtishi.Attributes.Add("class", swpAttributes[13]);
        tdtishi2.Attributes.Add("class", swpAttributes[13]); 
        tdtishi3.Attributes.Add("class", swpAttributes[13]); 
        tdthreetitle.Attributes.Add("class",swpAttributes[11]);

        tdtwo.Attributes.Add("class", swpAttributes[11]);
        tdtwoName.Attributes.Add("class", swpAttributes[11]);
        tdtwoName.Width = swpAttributes[4];

        tdtwoPsw.Attributes.Add("class", swpAttributes[11]);
        tdtwoPsw.Width = swpAttributes[4];

        tdanswer.Attributes.Add("class", swpAttributes[11]);
        txtAsnwer.CssClass = swpAttributes[12];

        tdemail.Attributes.Add("class", swpAttributes[11]);
        txtEmail.CssClass = swpAttributes[12];
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        InitlayOut();
        this.Two.Visible = false;
        this.Three.Visible = false;
    }

    /// <summary>
    /// 第一步(验证用户名是否存在)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibOK_Click(object sender, ImageClickEventArgs e)
    {
        //bool result = false;
        //DataTable dt = BLL.CustomerBLL.GetAllCustomerNo();
        //if (dt != null && dt.Rows.Count > 0)
        //{
        //    foreach (DataRow dr in dt.Rows)
        //    {
        //        if (dr["CustomerNo"].ToString() == txtUserName.Text)
        //        {
        //            result = true;
        //        }
        //    }
        //}
        //if (result == true)
        //{
        //    this.One.Visible = false;
        //    this.Two.Visible = true;
        //    this.Three.Visible = false;
        //    lbUserName.Text = txtUserName.Text;
        //    Session["UserName"] = lbUserName.Text;
        //    DataTable dts = BLL.CustomerBLL.GetCustomerIDByCustomerNo(txtUserName.Text);
        //    if (dts != null && dts.Rows.Count > 0)
        //    {
        //        DataRow dr = dts.Rows[0];
        //        long id = Shove._Convert.StrToLong(dr["ID"].ToString(), 0);
        //        Session["Password1"] = dr["Password1"].ToString();
        //        txtEmail.Text = dr["Email"].ToString();
        //        dts = BLL.CustomerBLL.GetQuestionAnswer(id);
        //        if (dts != null && dts.Rows.Count > 0)
        //        {
        //            dr = dts.Rows[0];
        //            lbQuestion.Text = dr["Question"].ToString();
        //            lbUserName.Text = txtUserName.Text;
        //            Session["Answer"] = dr["Answer"].ToString();
        //        }
        //    }
        //}
        //else
        //{
        //    this.One.Visible = true;
        //    this.Two.Visible = false;
        //    this.Three.Visible = false;
        //    this.UserName.InnerText = "此用户名不存在！";
        //}
    }

    /// <summary>
    /// 第二步(验证取回密码问答是否正确)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibCommit_Click(object sender, ImageClickEventArgs e)
    {
    //    DataTable dt = BLL.ShopSiteBLL.GetShopSiteInfo(this.SiteID);
    //    if (Session["Answer"] == null || txtAsnwer.Text == Session["Answer"].ToString())
    //    {
    //        this.One.Visible = false;
    //        this.Two.Visible = false;
    //        this.Three.Visible = true;
    //        DataTable emails = BLL.EmailBLL.GetEmail();

    //        string body = "您的用户名：" + Session["UserName"].ToString() + "<br/>" + "您的密码是:" + Session["Password1"].ToString() + "<br/>" + "请进入网站修改你的密码!" + "<br/>" + dt.Rows[0]["SiteURL"].ToString();
    //       int result = Shove._Net.Email.SendEmail(emails.Rows[0]["UserName"].ToString(), txtEmail.Text, "您的密码", body, emails.Rows[0]["EmailServer"].ToString(), emails.Rows[0]["UserName"].ToString(), emails.Rows[0]["Pwd"].ToString());
    //       if (result < 0)
    //       {
    //           Shove._Web.JavaScript.Alert(this.Page, "发送失败！");
    //       }
    //    }
    //    else
    //    {
    //        Shove._Web.JavaScript.Alert(this.Page, "输入的安全答案不正确！");
    //    }
    }
}
